# 保存为 ftp_server.py
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import os

# 创建测试目录
if not os.path.exists("D:/FTPTest"):
    os.makedirs("D:/FTPTest")

authorizer = DummyAuthorizer()
# 添加匿名用户
authorizer.add_anonymous("D:/FTPTest", perm="elradfmw")
# 添加有密码用户
authorizer.add_user("fff", "fff", "D:/FTPTest", perm="elradfmw")

handler = FTPHandler
handler.authorizer = authorizer

# 设置被动端口范围
handler.passive_ports = range(60000, 65535)

server = FTPServer(("0.0.0.0", 21), handler)
print("FTP服务器已启动在端口21...")
server.serve_forever()